using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data;

namespace 第九次作业
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }



        private static MySqlConnection GetConnection()
        {
            //SqlConnectionStringBuilder sqlConnectionString = new SqlConnectionStringBuilder();
            //sqlConnectionString.DataSource = "127.0.0.1";
            //sqlConnectionString.UserID = "root";
            //sqlConnectionString.Password = "xp20021114";
            //sqlConnectionString.InitialCatalog = "enwords";
            string ConnectionString = "server=localhost;user id=root;password=xp20021114;database=work9";
            MySqlConnection connection = new MySqlConnection(ConnectionString);
            connection.Open();
            return connection;
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            using (MySqlConnection connection = GetConnection())
            {
                string english = @"SELECT english FROM enwords
                WHERE chinese='苹果'";
                using (MySqlCommand cmd = new MySqlCommand(english, connection))
                {
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (reader.GetString(0) == this.textBox1.Text)
                            {
                                //check_baseball.Checked = true;
                                this.textBox1.AppendText("正确");
                            }
                            else
                            {
                                this.textBox1.AppendText("错误");
                            }
                        }
                    }
                }

                english = @"SELECT english FROM enwords
                WHERE chinese='香蕉'";
                using (MySqlCommand cmd = new MySqlCommand(english, connection))
                {
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (reader.GetString(0) == this.textBox1.Text)
                            {
                                //check_baseball.Checked = true;
                                this.textBox2.AppendText("正确");
                            }
                            else
                            {
                                this.textBox2.AppendText("错误");
                            }
                        }
                    }
                }

                english = @"SELECT english FROM enwords
                WHERE chinese='梨'";
                using (MySqlCommand cmd = new MySqlCommand(english, connection))
                {
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (reader.GetString(0) == this.textBox1.Text)
                            {
                                //check_baseball.Checked = true;
                                this.textBox3.AppendText("正确");
                            }
                            else
                            {
                                this.textBox3.AppendText("错误");
                            }
                        }
                    }
                }

                english = @"SELECT english FROM enwords
                WHERE chinese='西瓜'";
                using (MySqlCommand cmd = new MySqlCommand(english, connection))
                {
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (reader.GetString(0) == this.textBox1.Text)
                            {
                                //check_baseball.Checked = true;
                                this.textBox4.AppendText("正确");
                            }
                            else
                            {
                                this.textBox4.AppendText("错误");
                            }
                        }
                    }
                }
            }
        }
    }
}